package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "护理计划相关接口")
@RequestMapping("/nursing")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     * @return
     */
    @GetMapping("/plan")
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>> queryPlan() {
        List<NursingPlanVo> vo = nursingPlanService.queryPlan();
        return ResponseResult.success(vo);
    }

    /**
     * 分页查询
     */
    @GetMapping("/plan/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>> selectPlan(@ApiParam(name = "name", value = "护理计划名称") String name,
                                                                  @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                                                  @ApiParam(name = "status", value = "护理计划状态") Integer status
    ) {
        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.selectPlan(name, pageNum, pageSize, status);
        return ResponseResult.success(pageResponse);

    }

    /**
     * 新增护理计划
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增护理计划")
    @PostMapping("/plan")
    public ResponseResult addPlan(@RequestBody NursingPlanDto dto) {
        nursingPlanService.addPlan(dto);
        return ResponseResult.success();
    }

    /**
     * 根据id查询
     */
    @GetMapping("/plan/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingPlanVo> selectNursingPlan(@PathVariable Integer id) {
        NursingPlanVo vo = nursingPlanService.selectNursingPlan(id);
        return ResponseResult.success(vo);
    }

    /**
     * 修改
     */
    @PutMapping("/plan/{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult modifyNursingPlan(@RequestBody NursingPlanDto dto) {
        nursingPlanService.modifyNursingPlan(dto);
        return ResponseResult.success();
    }

    /**
     * 删除护理计划
     *
     * @param id
     * @return
     */
    @DeleteMapping("/plan/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult deleteNursingPlan(@PathVariable Integer id) {
        nursingPlanService.deleteNursingPlan(id);
        return ResponseResult.success();
    }

    /**
     * 启用禁用
     */
    @PutMapping("{id}/status/{status}")
    @ApiOperation("护理计划的启用禁用")
    public ResponseResult EnableDisableNursingPlan(@PathVariable Integer id,
                                                   @PathVariable Integer status) {
        nursingPlanService.EnableDisableNursingPlan(id, status);
        return ResponseResult.success();

    }
}
